﻿module Leaves.NeuroCryptography.ChaoticFunctions

let DefaultChaoticFunctionPower = 50

let ChaoticFunction q t x =
    let Chaotize x =
        match x with
        | _ when (0.0 <= x) && (x < q)          -> (x / q)
        | _ when (q <= x) && (x < 0.5)          -> (x - q) / (0.5 - q)
        | _ when (0.5 <= x) && (x < 1.0 - q)    -> (1.0 - q - x) / (0.5 - q)
        | _ when (1.0 - q <= x) && (x <= 1.0)   -> (1.0 - x) / q
        | _ when (x > 1.0) || (x < 0.0)          -> abs(x % 1.0)
        | _ -> failwith "x was not between 0.0 and 1.0"
     
    let mutable result = x
    for index in 1..t do
        result <- Chaotize result

    result

let EmptyChaoticFunction =
    ChaoticFunction 0.0 1

